<?php
$fmt = isset($_GET['fmt'])?$_GET['fmt']:'hls';
$r='https://www.qztv.cn/';
if($fmt=='hls'){
$id = isset($_GET['id'])?$_GET['id']:'qzxwzh';
$n = array(
  'qzxwzh' => ['wq95wqbDnMKyd8KiwqzChnt0w5nChcKowoHCoQ','news'] ,//泉州新闻综合
  'qzmny' => ['wq95wqbDnMKyd8KiwqzChnt0w5nChcKofcKh','mny'] ,//泉州闽南语
);
$data = file_get_contents('https://www.qztv.cn/index/Medias/index/media_id/'.$n[$id][0].'/stream_name/'.$n[$id][1].'.html');
preg_match('/urls = "https(.*?)"/',$data,$playurl);
$m3u8=m3u8('https'.$playurl[1],$r);
$phpself=substr($_SERVER['PHP_SELF'],strripos($_SERVER['PHP_SELF'],"/")+1);
header("Content-type: application/x-mpegURL");
echo str_replace('live.qztv.cn',$phpself.'?fmt=ts&ts=live.qztv.cn',$m3u8);
}else if($fmt=='ts'){
header("Content-type: video/mp2t");
$ts = $_GET['ts'];
$data = ts("https://live.qztv.cn/live/".trim($ts),$r);
}

function m3u8($url,$ref){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt ($ch, CURLOPT_REFERER, $ref);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
 
function ts($url,$ref){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt ($ch, CURLOPT_REFERER, $ref);
    $result = curl_exec($ch);
    curl_close($ch);
}
?>